package {
    import org.flixel.*;
    
    public class HUD extends FlxGroup {
        private var _text_score:FlxText = new FlxText(5, 5, 640, "score: 0");
        private var _last_score:int = 0;
        private var _sprite_tries:FlxGroup = new FlxGroup();
        private var _sprite_gauge:FlxGroup = new FlxGroup();
     
        public function HUD() {
            add(_text_score);
            add(_sprite_tries);
            add(_sprite_gauge);
        }   
     
        public function updateScore(score:int):void {
            if(_last_score != FlxG.score)
                _text_score.text = "score: " + score;
            _last_score = FlxG.score;
        }   
     
        public function updateTries(tries:int):void {
            _sprite_tries.destroy();
     
            for (var i:int = 1; i <= tries; i++) {
                var tmpSprite:FlxSprite = new FlxSprite((22 * i) - 15, 20);
                tmpSprite.alpha = 230;
                tmpSprite.loadGraphic(Resources.triesup); 
                _sprite_tries.add(tmpSprite);
            }   
        }   

        public function updateChargeBar(gauge:int):void {
            _sprite_gauge.destroy();
            for (var i:int = 1; i <= gauge; i++) {
                var tmpSprite:FlxSprite = new FlxSprite((4 * i) + 2, FlxG.height - 12);
                tmpSprite.alpha = 230;
                tmpSprite.loadGraphic(Resources.gauge); 
                _sprite_gauge.add(tmpSprite);
            }   
        }
     
        override public function update():void {
            updateScore(FlxG.score);
            super.update();
        }   
    }   
}

